<!DOCTYPE html>

<html>

    <head>

        <meta charset="utf-8">

        <title>

            文件管理

        </title>

        <meta name="renderer" content="webkit">

        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

        <meta name="apple-mobile-web-app-status-bar-style" content="black">

        <meta name="apple-mobile-web-app-capable" content="yes">

        <meta name="format-detection" content="telephone=no">

        <link href="__PUBLIC__/skin/nei.css" type="text/css" rel="stylesheet">                    

        <link rel="stylesheet" href="__PUBLIC__/skin/combo.select.css">           

    </head>

</head>
<body onLoad="initPage(),news()">
<div id="LoadingBar"><img src="__PUBLIC__/images/load.gif" /></div>
<div class="contaiter">	
	<div class="shuaxin" onclick="location.reload()" title="刷新">&#xe614;</div>
	<div class="nei03">
    	<form action="{:url('admin/files/index')}" method="post">   
            <div class="nei03_01">               	  	
            	<div class="nei03_01_01">
                    按大类：
                </div>
                <div class="nei03_01_02" style="width: 250px;">
                    <select name="cid" id="cid">
                        <option value="">不启用</option>    
                        {volist name="cateRes" id="vo"}
                            <option value="{$vo.id}"  {if condition="$cid eq $vo.id"} selected="selected" {/if}>{$vo.name}</option>
                        {/volist}
                    </select>   
                </div> 
                <div class="nei03_01_01">
                    按小类：
                </div>
                <div class="nei03_01_02" style="width: 250px;">
                    <select name="sid" id="sid">
                        <option value="">不启用</option>
                        {volist name="cateRes2" id="vo"}
                            <option value="{$vo.id}"  {if condition="$sid eq $vo.id"} selected="selected" {/if}>{$vo.name}</option>
                        {/volist}                            
                    </select>   
                </div> 
                <div class="nei03_01_03">
                    <input placeholder="请输入关键词" name="title" id="title" value="{$title}" class="layui-input-2">
                </div>
                <div class="nei03_01_03">
                    <button type="submit" class="layui-input-3 layui-btn-green"><i class="layui-icon" style="font-size:18px;color:#FFF;">&#xe615;</i></button>
                    <button type="button" class="layui-input-3 layui-btn-green"  onclick="resets()" style="margin-left: 5px; display: inline-block;"><i class="layui-icon" style="font-size:18px;color:#FFF;">重置</i></button>
                </div>
                </div>               

        </form>
        <div class="nei03_02 site-demo-button" style="margin-top: 20px;">
            <button class="layui-btn  layui-btn-1" onClick="openChuang('添加文件','{:url('admin/files/add')}')">+ 添加文件</button>
            <button class="layui-btn-2" onClick="openPiDelete()" ><i>&#xe6f4;</i><em>批量删除</em></button>  
        </div>
    </div>
    <div class="nei02">        
	   	<div class="nei02_01 l01">            
	   		<div class="nei02_01_07">            	
	   			<h3>                	
	   				<i><label><input type="checkbox"  id="checkall" name="checkall"><tt>✓</tt></label></i>
	   				<span class="s04">文件名称</span>
	   				<span class="s01">所属分类</span> 
	   				<span class="s02">文件大小</span>            	
	   				<span class="s02">排序</span>                    
	   				<span class="s02">添加时间</span>             
	   				<span class="s03"></span>                
	   				</h3>                
	   				<div class="nei02_01_07_01" id="list1">                
	   				</div>                
	   				<div class="nei02_01_04_02" id="pageDemo"></div>   
	   				<div style="float:right; margin-top:0px; margin-right:42%;">
		 		        <button class="layui-btn" style="width:60px; height:30px; line-height:30px; text-align:center;" onclick="vieworderPiDelete()"> 排序 </button> 
		 		    </div>         
	   		</div>        
	   	</div>           
	 </div>    

</div>   

<input type="hidden" id="pages1" name="pages1" value="1">

<input type="hidden" id="paiming" name="paiming" value="">
<input type="hidden" id="xuesheng" name="xuesheng" value="">
<script src="__PUBLIC__/js/jquery-1.10.2.min.js" type="application/javascript"></script>

<script src="__PUBLIC__/js/neijqtab.js" type="application/javascript"></script>

<script src="__PUBLIC__/js/xlayui/layui.js" charset="utf-8"></script>

<script src="__PUBLIC__/js/jquery.combo.select.js"></script>

<script>

$(function() {

	$('select').comboSelect();

});

</script>

<script>

function initPage(){   

	var objLoading = document.getElementById("LoadingBar");   

	if (objLoading != null){   

		objLoading.style.display = "none";   

		$(".contaiter").css("display","block");

	}   

}  

</script>

<script>

layui.use(['form','laypage', 'layer'], function(){ //独立版的layer无需执行这一句

  var $ = layui.jquery,form = layui.form(),laypage = layui.laypage, layer = layui.layer; //独立版的layer无需执行这一句     

});



function openChuang(title,url){	 

	 var othis = $(this), method = othis.data('method');

    //多窗口模式，层叠推荐

      layer.open({

        type: 2 //此处以iframe举例

        ,title: title

         ,area: ['100%', '100%']

        ,shade: 0

        ,maxmin: true

        ,offset: [ //为了演示，随机坐标

          $(window).height()-$(window).height()

          ,$(window).width()-$(window).width()

        ] 

        ,content: url      

      });  

}



function pageNum(id,total,pages){

	layui.use('laypage', function(){ //独立版的layer无需执行这一句

	var laypage = layui.laypage; //独立版的layer无需执行这一句  

	laypage({

		cont: id //分页容器的id

		,pages: total //总页数

		,skin: '#5FB878' //自定义选中色值

		,curr: pages //当前页

		,skip: true //开启跳页

		,jump: function(obj, first){

		if(!first){			

			layer.msg('第'+ obj.curr +'页',{time:300});

			if(id=="pageDemo") news(obj.curr);

		}

		}

		});	

	});		

}



function news(pages){		
	title = $("#title").val();
	cid = $("#cid").val();	
	sid = $("#sid").val();		
	$.ajax({		
	type: "POST",	
	async:false,		
	contentType:"application/x-www-form-urlencoded; charset=UTF-8",		
	url: "{:url('admin/files/lists')}",		
	data: {pagesize:9,pages:pages,title:title,cid:cid,sid:sid},		
	error:function(msg){ 
	alert("错误");		
	},		
	success:function(msg){	 
	json = msg.data;
	console.log(json);	 			 
	var html="";			 
	for(var i=0; i<json.length; i++){  	
	size = Math.ceil(json[i].filesize/1024);
	html += '<li><i><label><input type="checkbox" name="test" value="'+json[i].id+'"><tt>✓</tt></label></i><span class="s04">'+json[i].name+'</span><span class="s01">'+json[i].cname+'-'+json[i].sname+'</span><span class="s08">'+size+'kb</span><span class="s08"><input type="text" name="vieworder" value="'+json[i].vieworder+'" size="5" style="text-align:center;" /></span><span class="s08">'+json[i].addtime+'</span><span class="s02 layui-btn layui-btn-nonebg"  onClick=openChuang("信息编辑","__ROOT__/admin/files/edit/id/'+json[i].id+'")>&#xe617;</span><span class="s03 layui-btn layui-btn-nonebg-1" onclick=openDelete('+json[i].id+')>&#xe6f4;</span></li>';			 
	}  			
	$('#list1').html(html);			
	pageNum('pageDemo',msg.totalpage,pages);					
	if(pages>1)			 	
	$("#pages1").val(msg.totalpage);			
	else				
	$("#pages1").val(1);					 		
	}	
	});	

}


function openDelete(id){

	layer.confirm('确定要删除本条信息吗，删除无法恢复?', {icon: 3, title:'删除提示框'}, function(index){

		var loading2 = layer.load();			

		$.ajax({

			url:"__ROOT__/admin/files/delete",

			type:"POST",

			data:{id:id},

			dataType:"",

			success:function(json){

				layer.close(loading2);

				if(json==1){			

					layer.alert("删除成功!");		

					news($("#pages1").val());

				}else{

					layer.alert("删除失败",{time:1000});						

				}

				layer.close(index);

			},

			error:function(res){

				alert('删除语句错误!');

			}

		});		return false;

		

	});

}



function openAtrr(str,field,value){



	var obj=document.getElementsByName('test');

		var s=''; 

		for(var i=0; i<obj.length; i++){ 

		if(obj[i].checked) s+=obj[i].value+','; //如果选中，将value添加到变量s中 

		} 

	id=s.substring(0,s.length-1);

	if(id==''){

		layer.alert("请选择要"+str+"信息",{time:1000});

		return false;			

	}	

	layer.confirm('确定要'+str+'本条信息吗?', {icon: 3, title:''+str+'提示框'}, function(index){	

		var loading2 = layer.load();			

		$.ajax({

			url:"__ROOT__/admin/files/Atrr",

			type:"POST",

			data:{id:id,field:field,value:value},

			dataType:"",

			success:function(json){

				layer.close(loading2);

				if(json==1){			

					layer.alert(str+"成功!",{time:1000});		

					news($("#pages1").val());

				}else{

					layer.alert(str+"失败",{time:1000});						

				}

				layer.close(index);

			},

			error:function(res){

				alert(res);

			}

		});		

		return false;

		

	});

}

function openPiDelete(){

  str = "删除"; 

  var obj=document.getElementsByName('test');

    var s=''; 

    for(var i=0; i<obj.length; i++){ 

    if(obj[i].checked) s+=obj[i].value+','; //如果选中，将value添加到变量s中 

    } 

  id=s.substring(0,s.length-1); 

  if(id==''){

    layer.alert("请选择要"+str+"信息",{time:1000});

    return false;     

  } 

  layer.confirm('确定要'+str+'本条信息吗?', {icon: 3, title:''+str+'提示框'}, function(index){       

    $.ajax({

      url:"__ROOT__/admin/files/delete",

      type:"POST",

      data:{id:id},

      dataType:"",

      success:function(json){

        if(json==1){      

          layer.alert(str+"成功!");   

          news($("#pages1").val());

        }else{

          layer.alert(str+"失败",{time:1000});            

        }

        layer.close(index);

      },

      error:function(res){

        alert(res);

      }

    });   

    return false;

    

  });

}
function resets(){
	$("#title").val('');
	window.location.href="{:url('admin/files/index')}";

}

function vieworderPiDelete(){	

    			str = "排序";	

    			var obj=document.getElementsByName('test');	

    			var s=''; 		

    			for(var i=0; i<obj.length; i++){ 	

        			s+=obj[i].value+',';

    			} 	

    			id=s.substring(0,s.length-1);

    			var objs=document.getElementsByName('vieworder');

    			var vieworderStr=''; 		

    			for(var i=0; i<objs.length; i++){ 	

        			vieworderStr+=objs[i].value+',';

    			} 	

    			vieworder=vieworderStr.substring(0,vieworderStr.length-1);	

    			

    			layer.confirm('确定要'+str+'本条信息吗?', {icon: 3, title:''+str+'提示框'}, function(index){

    				$.ajax({	

    					url:"{:url('admin/files/vieworderFunc')}",

    					type:"POST",

    					data:{id:id,vieworder:vieworder},	

    					dataType:"",

    					success:function(json){	

    						if(json==1){	

    							layer.alert(str+"成功!");

    							news($("#pages1").val());

    						}else{			

    							layer.alert(str+"失败",{time:1000});

    						}			

    						layer.close(index);	

    					},			

    					error:function(res){	

    						alert(res);		

    					}	

    				});		

    				return false;	

    			});

    

    		}

 $("#cid").change(function(){



	      var cid = $("#cid").val();



	      $.getJSON("__ROOT__/admin/Category/getType/cid/"+cid, function(res){



				   var html="";



	               json = res.data;



				   for(var i=0; i<json.length; i++)   



					 {  



					    html +='<option value="'+json[i].id+'">'+json[i].name+'</option>';



					 } 



				  $("select[name='sid']").html('<option value="">可搜索选择</option>'+html);



				  $('select').comboSelect();



	 			   



	      });



	   });   
</script>

</body>

</html>

